home *** CD-ROM | disk | FTP | other *** search
/ Amiga News 95 / Amiga News 95.iso / dpat / dpat64 / screen2iff / screen2iff.s < prev    next >
Text File  |  1994-01-22  |  18KB  |  898 lines

  1.     opt    AMIGA
  2. ;* $Revision Header built automatically *************** (do not edit) ************
  3. ;*
  4. ;* © Copyright by F.Delacroix
  5. ;*
  6. ;* File             : DH0{42MB}:Progs/ScreenSaver/Screen2IFF.s
  7. ;* Created on       : Samedi, 22-Jan-94   16:47:02
  8. ;* Created by       : Frédéric DELACROIX
  9. ;* Current revision : V1.00
  10. ;*
  11. ;*
  12. ;* Purpose
  13. ;* -------
  14. ;*     This commodity saves the front screen to disk (in IFF ILBM
  15. ;*     format) when hotkey is pressed. Supports some WB & CLI
  16. ;*     options. Written on Hisoft's Devpac 3.
  17. ;*
  18. ;* Revision V1.00
  19. ;* --------------
  20. ;*     --- Initial release ---
  21. ;*
  22. ;*********************************************************************************
  23. REVISION  MACRO
  24.           dc.b "1.00"
  25.           ENDM
  26. REVDATE   MACRO
  27.           dc.b "22-Jan-94  "
  28.           ENDM
  29. REVTIME   MACRO
  30.           dc.b "16:47:02"
  31.           ENDM
  32. AUTHOR    MACRO
  33.           dc.b "Frédéric DELACROIX"
  34.           ENDM
  35. VERNUM    EQU  01
  36. REVNUM    EQU  00
  37.  
  38.     include    exec/execbase.i
  39.     include    exec/alerts.i
  40.     include    libraries/commodities.i
  41.     include    libraries/commodities_lib.i
  42.     include    dos/dostags.i
  43.     include    workbench/icon_lib.i
  44.     include    workbench/workbench.i
  45.     include    libraries/iffparse.i
  46.     include    libraries/iffparse_lib.i
  47.     include    graphics/layers_lib.i
  48.  
  49. IE_SAVESCREEN    EQU    1
  50. ;DEBUG    SET    1
  51.  
  52. Start    move.l    4.w,a6
  53.     move.l    ThisTask(a6),a4
  54.     tst.l    pr_CLI(a4)
  55.     bne.s    FromCLI
  56.     lea    pr_MsgPort(a4),a0
  57.     jsr    _LVOWaitPort(a6)
  58.     lea    pr_MsgPort(a4),a0
  59.     jsr    _LVOGetMsg(a6)
  60.     move.l    d0,WB.Startup
  61.  
  62. FromCLI    lea    Intuition.Name(pc),a1
  63.     jsr    _LVOOldOpenLibrary(a6)
  64.     move.l    d0,Intuition.Base
  65.     bne.s    IntuitionOK
  66.     move.l    #AT_Recovery!AG_OpenLib!AO_Intuition,d7
  67.     jsr    _LVOAlert(a6)
  68.     bra    exit
  69. IntuitionOK
  70.     move.l    d0,a1
  71.     cmp.w    #37,LIB_VERSION(a1)
  72.     bge.s    KickOK
  73.     move.l    a1,a6
  74.     move.l    #RECOVERY_ALERT,d0
  75.     lea    BadKickstart.ALT,a0
  76.     move.l    #BadKickstart.HGT,d1
  77.     jsr    _LVODisplayAlert(a6)
  78.     bra.s    CloseIntuition
  79.  
  80. KickOK    lea    DOS.Name(pc),a1
  81.     moveq    #37,d0
  82.     jsr    _LVOOpenLibrary(a6)
  83.     move.l    d0,DOS.Base
  84.     bne.s    DOSOK
  85.     move.l    #AT_Recovery!AG_OpenLib!AO_DOSLib,d7
  86.     jsr    _LVOAlert(a6)
  87.     bra.s    CloseIntuition
  88.  
  89. DOSOK    bsr.s    ReadArgs
  90.     IFD    DEBUG
  91.     jmp    Resident
  92.     ENDC
  93.     lea    Start-4(pc),a0
  94.     move.l    (a0),Child.SegList
  95.     clr.l    (a0)
  96.     move.l    #NewProc.Tags,d1
  97.     move.l    DOS.Base,a6
  98.     jsr    _LVOCreateNewProc(a6)
  99.     tst.l    d0
  100.     beq.s    CloseDOS
  101.     bra.s    exit
  102. CloseDOS
  103.     bsr    SmallCleanUp
  104.     move.l    DOS.Base,a1
  105.     move.l    4.w,a6
  106.     jsr    _LVOCloseLibrary(a6)
  107. CloseIntuition
  108.     move.l    Intuition.Base,a1
  109.     move.l    4.w,a6
  110.     jsr    _LVOCloseLibrary(a6)
  111. exit    move.l    WB.Startup(pc),d0
  112.     beq.s    ExitToCLI
  113.     move.l    4.w,a6
  114.     jsr    _LVOForbid(a6)
  115.     move.l    d0,a1
  116.     jsr    _LVOReplyMsg(a6)
  117. ExitToCLI
  118.     moveq    #0,d0
  119.     rts
  120.  
  121. ReadArgs
  122.     tst.l    WB.Startup
  123.     bne.s    .WBArgs
  124.     move.l    #Args.Template,d1
  125.     move.l    #Args.Array,d2
  126.     moveq    #0,d3
  127.     move.l    DOS.Base,a6
  128.     jsr    _LVOReadArgs(a6)
  129.     move.l    d0,Args.RDArgs
  130.     rts
  131.  
  132. .WBArgs    lea    Icon.Name,a1
  133.     moveq    #37,d0
  134.     move.l    4.w,a6
  135.     jsr    _LVOOpenLibrary(a6)
  136.     move.l    d0,Icon.Base
  137.     beq.s    .NoIconLib
  138.     move.l    WB.Startup(pc),a2
  139.     tst.l    sm_NumArgs(a2)
  140.     beq.s    .NoIconLib
  141.     move.l    sm_ArgList(a2),d0
  142.     beq.s    .NoIconLib
  143.     move.l    d0,a2
  144.     move.l    wa_Lock(a2),d1
  145.     move.l    DOS.Base,a6
  146.     jsr    _LVOCurrentDir(a6)
  147.     move.l    wa_Name(a2),a0
  148.     move.l    Icon.Base,a6
  149.     jsr    _LVOGetDiskObject(a6)
  150.     move.l    d0,Program.DiskObject
  151.     beq.s    .NoIconLib
  152.     move.l    d0,a2
  153.  
  154.     lea    HotKey.TT(pc),a1
  155.     move.l    do_ToolTypes(a2),a0
  156.     jsr    _LVOFindToolType(a6)
  157.     move.l    d0,SaveScreen.Descr
  158.  
  159.     lea    BaseName.TT(pc),a1
  160.     move.l    do_ToolTypes(a2),a0
  161.     jsr    _LVOFindToolType(a6)
  162.     move.l    d0,BaseName
  163.  
  164.     lea    CXPri.TT(pc),a1
  165.     move.l    do_ToolTypes(a2),a0
  166.     jsr    _LVOFindToolType(a6)
  167.     move.l    d0,d1
  168.     move.l    #CXPri,d2
  169.     move.l    DOS.Base,a6
  170.     jsr    _LVOStrToLong(a6)
  171. .NoIconLib
  172.     rts
  173.  
  174. SmallCleanUp
  175.     move.l    Program.DiskObject,d0
  176.     beq.s    .NoDiskOb
  177.     move.l    Icon.Base,a6
  178.     move.l    d0,a0
  179.     jsr    _LVOFreeDiskObject(a6)
  180. .NoDiskOb
  181.     move.l    Args.RDArgs,d1
  182.     beq.s    .NoRDArgs
  183.     move.l    DOS.Base,a6
  184.     jsr    _LVOFreeArgs(a6)
  185. .NoRDArgs
  186.     move.l    Icon.Base,d0
  187.     beq.s    .NoIcon
  188.     move.l    d0,a1
  189.     move.l    4.w,a6
  190.     jsr    _LVOCloseLibrary(a6)
  191. .NoIcon    rts
  192.  
  193.  
  194. WB.Startup    dc.l    0
  195. NewProc.Tags    dc.l    NP_Seglist
  196. Child.SegList    dc.l    0
  197.     dc.l    NP_Name,Screen2IFF.Name
  198.     dc.l    NP_Priority,2
  199.     dc.l    NP_WindowPtr,0
  200.     dc.l    TAG_DONE
  201.  
  202. DOS.Name    dc.b    'dos.library',0
  203. Intuition.Name    dc.b    'intuition.library',0
  204. Args.Template    dc.b    'HOTKEY,BASENAME,CXPRI/N',0
  205. HotKey.TT    dc.b    'HOTKEY',0
  206. BaseName.TT    dc.b    'BASENAME',0
  207. CXPri.TT    dc.b    'CXPRI',0
  208.  
  209.     section    Resident,CODE
  210. Resident
  211.     lea    Graphics.Name(pc),a1
  212.     moveq    #37,d0
  213.     move.l    4.w,a6
  214.     jsr    _LVOOpenLibrary(a6)
  215.     move.l    d0,Graphics.Base
  216.     bne.s    GraphicsOK
  217.     move.l    #AT_Recovery!AG_OpenLib!AO_GraphicsLib,d7
  218.     jsr    _LVOAlert(a6)
  219.     bra    CloseDOSResident
  220.  
  221. GraphicsOK
  222.     lea    Layers.Name(pc),a1
  223.     moveq    #37,d0
  224.     jsr    _LVOOpenLibrary(a6)
  225.     move.l    d0,Layers.Base
  226.     bne.s    LayersOK
  227.     move.l    #AT_Recovery!AG_OpenLib!AO_LayersLib,d7
  228.     jsr    _LVOAlert(a6)
  229.     bra    CloseGraphics
  230.  
  231. LayersOK
  232.     lea    Commodities.Name(pc),a1
  233.     moveq    #37,d0
  234.     jsr    _LVOOpenLibrary(a6)
  235.     move.l    d0,Commodities.Base
  236.     bne.s    CommoditiesOK
  237.     lea    NoCommodities.MSG(pc),a0
  238.     bsr    Print
  239.     bra.s    CloseLayers
  240. CommoditiesOK
  241.     lea    IFFParse.Name(pc),a1
  242.     moveq    #37,d0
  243.     jsr    _LVOOpenLibrary(a6)
  244.     move.l    d0,IFFParse.Base
  245.     bne.s    IFFParseOK
  246.     lea    NoIFFParse.MSG(pc),a0
  247.     bsr    Print
  248.     bra.s    CloseCommodities
  249. IFFParseOK
  250.     move.l    d0,a6
  251.     jsr    _LVOAllocIFF(a6)
  252.     move.l    d0,SaveFile.IFF
  253.     bne.s    IFFOK
  254.     lea    NotEnoughMem.MSG(pc),a0
  255.     bsr.s    Print
  256.     bra.s    CloseIFFParse
  257. IFFOK    move.l    d0,a0
  258.     jsr    _LVOInitIFFasDOS(a6)
  259.  
  260.     bsr    SetCommodity
  261.     tst.l    d0
  262.     beq.s    CloseCommodities
  263.     bsr    ProcessMessages
  264.     bsr    RemCommodity
  265.  
  266. FreeIFF    move.l    SaveFile.IFF(pc),a0
  267.     move.l    IFFParse.Base(pc),a6
  268.     jsr    _LVOFreeIFF(a6)
  269. CloseIFFParse
  270.     move.l    IFFParse.Base(pc),a1
  271.     move.l    4.w,a6
  272.     jsr    _LVOCloseLibrary(a6)
  273. CloseCommodities
  274.     move.l    Commodities.Base(pc),a1
  275.     move.l    4.w,a6
  276.     jsr    _LVOCloseLibrary(a6)
  277. CloseLayers
  278.     move.l    Layers.Base(pc),a1
  279.     move.l    4.w,a6
  280.     jsr    _LVOCloseLibrary(a6)
  281. CloseGraphics
  282.     move.l    Graphics.Base(pc),a1
  283.     move.l    4.w,a6
  284.     jsr    _LVOCloseLibrary(a6)
  285. CloseDOSResident
  286.     move.l    DOS.Base(pc),a1
  287.     move.l    4.w,a6
  288.     jsr    _LVOCloseLibrary(a6)
  289.     move.l    Intuition.Base(pc),a1
  290.     move.l    4.w,a6
  291.     jsr    _LVOCloseLibrary(a6)
  292.     moveq    #0,d0
  293.     rts
  294.  
  295. Print    movem.l    d0-d1/a0-a3/a6,-(sp)    ; Print(Message)(A0)
  296.     lea    EasyPrint(pc),a1
  297.     move.l    a0,es_TextFormat(a1)
  298.     suba.l    a0,a0
  299.     move.l    a0,a2
  300.     move.l    a2,a3
  301.     move.l    Intuition.Base(pc),a6
  302.     jsr    _LVOEasyRequestArgs(a6)
  303.     movem.l    (sp)+,d0-d1/a0-a3/a6
  304.     rts
  305.  
  306. SetCommodity    ; (D0)Success=SetCommodity()
  307.     move.l    4.w,a6
  308.     jsr    _LVOCreateMsgPort(a6)
  309.     lea    Screen2IFF.NewBroker(pc),a0
  310.     move.l    d0,nb_Port(a0)
  311.     bne.s    .PortOK
  312.     lea    NotEnoughMem.MSG(pc),a0
  313.     bsr    Print
  314.     bra.s    .Failure
  315.  
  316. .PortOK    move.l    CXPri(pc),d0
  317.     beq.s    .NoPri
  318.     move.l    d0,a1
  319.     move.b    3(a1),nb_Pri(a0)
  320. .NoPri    move.l    #CXError,d0
  321.     move.l    Commodities.Base(pc),a6
  322.     jsr    _LVOCxBroker(a6)
  323.     move.l    d0,CXBroker
  324.     bne.s    .BrokerOK
  325.     move.l    CXError(pc),d0
  326.     cmp.l    #CBERR_SYSERR,d0
  327.     beq.s    .NoMem
  328.     cmp.l    #CBERR_DUP,d0
  329.     beq.s    .Removed
  330.     lea    UnknownCXError.MSG(pc),a0
  331.     bra.s    .ErrorDone
  332. .Removed
  333.     lea    Removed.MSG(pc),a0
  334.     bra.s    .ErrorDone
  335. .NoMem    lea    NotEnoughMem.MSG(pc),a0
  336. .ErrorDone
  337.     bsr    Print
  338.     bra.s    .Failure
  339.  
  340. .BrokerOK
  341.     lea    SaveScreen.HKD(pc),a0
  342.     bsr.s    CreateHotKey
  343.     move.l    d0,SaveScreen.HK
  344.     beq.s    .Failure
  345.  
  346.     move.l    CXBroker(pc),a0
  347.     moveq    #-1,d0
  348.     move.l    Commodities.Base(pc),a6
  349.     jsr    _LVOActivateCxObj(a6)
  350.  
  351.     moveq    #-1,d0
  352.     rts
  353.  
  354. .Failure
  355.     move.l    CXBroker(pc),a0
  356.     bsr    DeleteObj
  357.     move.l    CXPort(pc),d0
  358.     beq.s    .NoPortToRemove
  359.     move.l    d0,a0
  360.     move.l    4.w,a6
  361.     jsr    _LVODeleteMsgPort(a6)
  362. .NoPortToRemove
  363.     moveq    #0,d0
  364.     rts
  365.  
  366. ; hotkey description structure
  367.     rsreset
  368. HKD_ID    rs.l    1
  369. HKD_Current    rs.l    1    ; (pointer to pointer to string)
  370. HKD_Default    rs.l    1
  371. HKD_SIZEOF    rs.w    0
  372.  
  373. CreateHotKey    ; (D0)(Filter)=CreateHotKey(Descr)(A0)
  374.     movem.l    d2/a0-a3/a6,-(sp)
  375.     move.l    a0,a2
  376.     moveq    #CX_FILTER,d0
  377.     move.l    HKD_Current(a2),a0
  378.     move.l    (a0),d1
  379.     bne.s    .DescOK
  380.     move.l    HKD_Default(a2),d1
  381. .DescOK    move.l    d1,a0
  382.     suba.l    a1,a1
  383.     move.l    Commodities.Base(pc),a6
  384.     jsr    _LVOCreateCxObj(a6)
  385.     move.l    d0,d2
  386.     beq.s    .NoFilter
  387.     move.l    d2,a0
  388.     jsr    _LVOCxObjError(a6)
  389.     cmp.l    #COERR_BADFILTER,d0
  390.     bne.s    .DescrOK
  391.     lea    BadHotKeyDescr.MSG(pc),a0
  392.     bsr    Print
  393.     move.l    HKD_Default(a2),a1
  394.     move.l    d2,d0
  395.     jsr    _LVOSetFilter(a6)
  396. .DescrOK
  397.     moveq    #CX_SEND,d0
  398.     move.l    CXPort(pc),a0
  399.     move.l    HKD_ID(a2),a1
  400.     jsr    _LVOCreateCxObj(a6)
  401.     move.l    d0,a1
  402.     move.l    a1,d0
  403.     beq.s    .NoSender
  404.     move.l    d2,a0
  405.     jsr    _LVOAttachCxObj(a6)
  406.     moveq    #CX_TRANSLATE,d0
  407.     suba.l    a0,a0
  408.     move.l    a0,a1
  409.     jsr    _LVOCreateCxObj(a6)
  410.     move.l    d2,a0
  411.     move.l    d0,a1
  412.     move.l    a1,d0
  413.     beq.s    .NoTranslate
  414.     jsr    _LVOAttachCxObj(a6)
  415.     move.l    d2,a1
  416.     move.l    CXBroker(pc),a0
  417.     jsr    _LVOAttachCxObj(a6)
  418.     move.l    d2,d0
  419.     movem.l    (sp)+,d2/a0-a3/a6
  420.     rts
  421.  
  422. .NoTranslate
  423. .NoSender
  424.     move.l    d2,a0
  425.     jsr    _LVODeleteCxObjAll(a6)
  426. .NoFilter
  427.     lea    NotEnoughMem.MSG(pc),a0
  428.     bsr    Print
  429.     movem.l    (sp)+,d2-d3/a0-a3/a6
  430.     moveq    #0,d0
  431.     move.l    d0,d1
  432.     rts
  433.  
  434. DeleteObj    ; DeleteObj(Object)(A0)
  435.     movem.l    d0-d1/a0-a1/a6,-(sp)
  436.     move.l    Commodities.Base(pc),a6
  437.     jsr    _LVODeleteCxObjAll(a6)
  438.     movem.l    (sp)+,d0-d1/a0-a1/a6
  439.     rts
  440.  
  441. RemCommodity
  442.     move.l    CXBroker(pc),a0
  443.     bsr    DeleteObj
  444.     move.l    4.w,a6
  445. .MsgLoop
  446.     move.l    CXPort(pc),a0
  447.     jsr    _LVOGetMsg(a6)
  448.     move.l    d0,a1
  449.     move.l    a1,d0
  450.     beq.s    .EndOfMsg
  451.     jsr    _LVOReplyMsg(a6)
  452.     bra.s    .MsgLoop
  453. .EndOfMsg
  454.     move.l    CXPort(pc),a0
  455.     jsr    _LVODeleteMsgPort(a6)
  456.     rts
  457.  
  458. ProcessMessages
  459.     move.l    CXPort(pc),a0
  460.     move.l    4.w,a6
  461.     jsr    _LVOWaitPort(a6)
  462. GetCXMessage
  463.     move.l    CXPort(pc),a0
  464.     move.l    4.w,a6
  465.     jsr    _LVOGetMsg(a6)
  466.     move.l    d0,a2
  467.     move.l    a2,d0
  468.     beq.s    ProcessMessages
  469.     move.l    a2,a0
  470.     move.l    Commodities.Base(pc),a6
  471.     jsr    _LVOCxMsgType(a6)
  472.     move.l    d0,d2
  473.     move.l    a2,a0
  474.     jsr    _LVOCxMsgID(a6)
  475.     move.l    d0,d3
  476.     move.l    a2,a1
  477.     move.l    4.w,a6
  478.     jsr    _LVOReplyMsg(a6)
  479.     cmp.l    #CXM_COMMAND,d2
  480.     beq.s    ProcessCommand
  481.     cmp.l    #CXM_IEVENT,d2
  482.     beq.s    ProcessEvent
  483.     lea    UnknownCXMessage.MSG,a0
  484.     bsr    Print
  485.     bra.s    GetCXMessage
  486. ProcessCommand
  487.     cmp.l    #CXCMD_DISABLE,d3
  488.     beq.s    .Disable
  489.     cmp.l    #CXCMD_ENABLE,d3
  490.     beq.s    .Enable
  491.     cmp.l    #CXCMD_UNIQUE,d3
  492.     beq.s    .Kill
  493.     cmp.l    #CXCMD_KILL,d3
  494.     beq.s    .Kill
  495.     lea    UnknownCXMessage.MSG,a0
  496.     bsr    Print
  497.     bra.s    GetCXMessage
  498. .Disable
  499.     moveq    #0,d0
  500.     bra.s    .ActBro
  501. .Enable    moveq    #-1,d0
  502. .ActBro    move.l    CXBroker(pc),a0
  503.     move.l    Commodities.Base(pc),a6
  504.     jsr    _LVOActivateCxObj(a6)
  505.     bra    GetCXMessage
  506. .Kill    rts
  507.  
  508. ProcessEvent
  509.     cmp.l    #IE_SAVESCREEN,d3
  510.     bne.s    .NoSaveScreen
  511.     bsr.s    SaveScreen
  512. .NoSaveScreen
  513.     bra    GetCXMessage
  514.  
  515.  
  516. SaveScreen
  517.     move.l    Intuition.Base(pc),a6
  518.     IFND    DEBUG
  519.     moveq    #0,d0
  520.     jsr    _LVOLockIBase(a6)
  521.     move.l    d0,d2
  522.     ENDC
  523.     move.l    ib_FirstScreen(a6),a5
  524.     IFND    DEBUG
  525.     move.l    4.w,a6
  526.     jsr    _LVOForbid(a6)
  527.     move.l    Intuition.Base(pc),a6
  528.     move.l    d2,a0
  529.     jsr    _LVOUnlockIBase(a6)
  530.  
  531.     lea    sc_LayerInfo(a5),a0
  532.     move.l    Layers.Base(pc),a6
  533.     jsr    _LVOLockLayerInfo(a6)
  534.     move.l    4.w,a6
  535.     jsr    _LVOPermit(a6)
  536.     ENDC
  537.  
  538. ; lets copy the bitplanes into fresh memory while screen is locked
  539. DebugHere
  540.     move.l    sc_RastPort+rp_BitMap(a5),a4
  541.     moveq    #0,d0
  542.     move.l    d0,d1
  543.     move.w    bm_BytesPerRow(a4),d0
  544.     move.w    bm_Rows(a4),d1
  545.     mulu    d1,d0
  546.     move.l    d0,d7            ; d7= Plane size
  547.     moveq    #0,d6
  548.     move.b    bm_Depth(a4),d6        ; d6= Depth
  549.     lsl.l    d6,d0
  550.     move.l    d0,Body.Size
  551.     move.l    #MEMF_PUBLIC,d1
  552.     move.l    4.w,a6
  553.     jsr    _LVOAllocVec(a6)
  554.     move.l    d0,a3            ; a3= Copy of bitplanes (interleaved)
  555.     move.l    a3,Bitplanes.Copy
  556.     bne.s    .MemOK
  557.     bsr    SurrenderLI
  558.     lea    NotEnoughMem.MSG(pc),a0
  559.     bra    Print
  560. .MemOK
  561.     moveq    #0,d7            ; line offset
  562.     move.l    d7,d6
  563.     move.w    bm_BytesPerRow(a4),d6    ; byte counter
  564.     move.w    bm_Rows(a4),d5        ; line counter
  565.     subq.w    #1,d5
  566. .NextLine
  567.     moveq    #0,d4            ; plane counter
  568.     move.b    bm_Depth(a4),d4
  569.     subq.w    #1,d4
  570.     lea    bm_Planes(a4),a0    ; plane pointer pointer
  571. .NextPlane
  572.     move.l    (a0)+,a1        ; plane pointer
  573.     add.l    d7,a1            ; point right line
  574.     move.l    d6,d3        ; number of bytes to transfer
  575.     subq.l    #1,d3
  576. .CopyLoop
  577.     move.b    (a1)+,(a3)+
  578.     dbra    d3,.CopyLoop
  579.     dbra    d4,.NextPlane
  580.     add.l    d6,d7
  581.     dbra    d5,.NextLine
  582.  
  583.     moveq    #0,d0
  584.     move.w    bm_BytesPerRow(a4),d0
  585.     lsl.l    #3,d0
  586.     move.w    d0,BMHD.Wid
  587.     move.w    d0,BMHD.pageWidth
  588.     moveq    #0,d1
  589.     move.w    bm_Rows(a4),BMHD.H
  590.     move.w    bm_Rows(a4),BMHD.pageHeight
  591.     move.b    bm_Depth(a4),BMHD.nPlanes
  592.  
  593.     moveq    #1,d3
  594.     moveq    #0,d1
  595.     move.b    bm_Depth(a4),d1
  596.     lsl.l    d1,d3
  597.     move.l    d3,NColors
  598.     move.l    d3,d0
  599.     mulu    #3,d0
  600.     move.l    #MEMF_CLEAR,d1
  601.     move.l    4.w,a6
  602.     jsr    _LVOAllocVec(a6)
  603.     move.l    d0,CMap
  604.     bne.s    .CMAPAllocated
  605.     bsr    SurrenderLI
  606.     lea    NotEnoughMem.MSG(pc),a0
  607.     bsr    Print
  608.     bra    .FreeBODY
  609. .CMAPAllocated
  610.     move.l    d0,a2
  611.     move.l    sc_ViewPort+vp_ColorMap(a5),a3
  612.     move.l    Graphics.Base(pc),a6
  613.     subq.l    #1,d3
  614. .FillCMap
  615.     move.l    NColors(pc),d0
  616.     sub.l    d3,d0
  617.     subq.l    #1,d0
  618.     move.l    a3,a0
  619.     jsr    _LVOGetRGB4(a6)
  620.     move.l    d0,d1
  621.     and.l    #%0000111100000000,d0
  622.     lsr.l    #4,d0
  623.     move.b    d0,(a2)+
  624.     move.l    d1,d0
  625.     and.l    #%0000000011110000,d0
  626.     move.b    d0,(a2)+
  627.     move.l    d1,d0
  628.     and.l    #%0000000000001111,d0
  629.     lsl.l    #4,d0
  630.     move.b    d0,(a2)+
  631.     dbra    d3,.FillCMap
  632.  
  633.     move.w    sc_ViewPort+vp_Modes(a5),d0
  634.     and.l    #(~(V_SPRITES|GENLOCK_VIDEO))&$FFFF,d0
  635.     move.l    d0,CAMG
  636.     bsr    SurrenderLI
  637.  
  638. .TryThisFile
  639.     move.l    BaseName(pc),d1
  640.     move.l    #MODE_OLDFILE,d2
  641.     move.l    DOS.Base(pc),a6
  642.     jsr    _LVOOpen(a6)
  643.     move.l    d0,d1
  644.     beq.s    .ThisFile
  645.     jsr    _LVOClose(a6)
  646.     move.l    BaseName(pc),a0
  647.     bsr    StrLen
  648.     move.b    -1(a0,d0),d1
  649.     addq.b    #1,d1
  650.     cmp.b    #'Z',d1
  651.     ble.s    .NotZ
  652.     move.b    #'A',d1
  653. .NotZ    move.b    d1,-1(a0,d0)
  654.     bra.s    .TryThisFile
  655.  
  656. .ThisFile
  657.     move.l    BaseName(pc),d1
  658.     move.l    #MODE_NEWFILE,d2
  659.     jsr    _LVOOpen(a6)
  660.     move.l    d0,SaveFile.Handle
  661.     bne.s    .SaveFileOpened
  662.     lea    CantOpenSaveFile.MSG(pc),a0
  663.     bsr    Print
  664.     bra    .FreeCMAP
  665. .SaveFileOpened
  666.     move.l    SaveFile.IFF(pc),a0
  667.     move.l    d0,iff_Stream(a0)
  668.     move.l    #IFFF_WRITE,d0
  669.     move.l    IFFParse.Base(pc),a6
  670.     jsr    _LVOOpenIFF(a6)
  671.     tst.l    d0
  672.     beq.s    .IFFOpened
  673.     lea    CantOpenSaveFile.MSG(pc),a0
  674.     bsr    Print
  675.     bra    .CloseFile
  676. .IFFOpened
  677.     move.l    SaveFile.IFF(pc),a0
  678.     move.l    #'ILBM',d0
  679.     move.l    #'FORM',d1
  680.     move.l    #IFFSIZE_UNKNOWN,d2
  681.     jsr    _LVOPushChunk(a6)
  682.     tst.l    d0
  683.     beq.s    .FORMPushed
  684. .IFFError
  685.     lea    ErrorWriting.MSG(pc),a0
  686.     bsr    Print
  687.     bra    .CloseIFF
  688. .FORMPushed
  689.     move.l    SaveFile.IFF(pc),a0    ; let's create BMHD
  690.     move.l    #'BMHD',d1
  691.     move.l    #BMHD.SIZEOF,d2
  692.     jsr    _LVOPushChunk(a6)
  693.     tst.l    d0
  694.     bne.s    .IFFError
  695.     lea    BMHD.Buffer(pc),a1
  696.     move.l    SaveFile.IFF(pc),a0
  697.     move.l    d2,d0
  698.     jsr    _LVOWriteChunkBytes(a6)
  699.     cmp.l    d0,d2
  700.     bne.s    .IFFError
  701.     move.l    SaveFile.IFF(pc),a0
  702.     jsr    _LVOPopChunk(a6)
  703.     tst.l    d0
  704.     bne.s    .IFFError
  705.  
  706.     move.l    SaveFile.IFF(pc),a0        ; go CAMG
  707.     move.l    #'CAMG',d1
  708.     move.l    #4,d2
  709.     jsr    _LVOPushChunk(a6)
  710.     tst.l    d0
  711.     bne.s    .IFFError
  712.     lea    CAMG(pc),a1
  713.     move.l    SaveFile.IFF(pc),a0
  714.     move.l    d2,d0
  715.     jsr    _LVOWriteChunkBytes(a6)
  716.     cmp.l    d0,d2
  717.     bne.s    .IFFError
  718.     move.l    SaveFile.IFF(pc),a0
  719.     jsr    _LVOPopChunk(a6)
  720.     tst.l    d0
  721.     bne.s    .IFFError
  722.  
  723.     move.l    SaveFile.IFF(pc),a0        ; we're going to write the CMAP
  724.     move.l    #'CMAP',d1
  725.     move.l    NColors(pc),d2
  726.     mulu    #3,d2
  727.     jsr    _LVOPushChunk(a6)
  728.     tst.l    d0
  729.     bne    .IFFError
  730.     move.l    SaveFile.IFF(pc),a0
  731.     move.l    CMap(pc),a1
  732.     move.l    d2,d0
  733.     jsr    _LVOWriteChunkBytes(a6)
  734.     cmp.l    d0,d2
  735.     bne    .IFFError
  736.     move.l    SaveFile.IFF(pc),a0
  737.     jsr    _LVOPopChunk(a6)
  738.     tst.l    d0
  739.     bne    .IFFError
  740.     
  741.     move.l    SaveFile.IFF(pc),a0        ; the big one: BODY
  742.     move.l    #'BODY',d1
  743.     move.l    Body.Size(pc),d2
  744.     jsr    _LVOPushChunk(a6)
  745.     tst.l    d0
  746.     bne    .IFFError
  747.     move.l    SaveFile.IFF(pc),a0
  748.     move.l    Bitplanes.Copy(pc),a1
  749.     move.l    d2,d0
  750.     jsr    _LVOWriteChunkBytes(a6)
  751.     cmp.l    d2,d0
  752.     bne    .IFFError
  753.     move.l    SaveFile.IFF(pc),a0
  754.     jsr    _LVOPopChunk(a6)
  755.     tst.l    d0
  756.     bne    .IFFError
  757.  
  758.     move.l    SaveFile.IFF(pc),a0
  759.     jsr    _LVOPopChunk(a6)
  760.     tst.l    d0
  761.     bne    .IFFError
  762.  
  763. .CloseIFF
  764.     move.l    SaveFile.IFF(pc),a0
  765.     move.l    IFFParse.Base(pc),a6
  766.     jsr    _LVOCloseIFF(a6)
  767. .CloseFile
  768.     move.l    SaveFile.Handle(pc),d1
  769.     move.l    DOS.Base(pc),a6
  770.     jsr    _LVOClose(a6)
  771. .FreeCMAP
  772.     move.l    CMap(pc),a1
  773.     move.l    4.w,a6
  774.     jsr    _LVOFreeVec(a6)    
  775. .FreeBODY
  776.     move.l    Bitplanes.Copy(pc),a1
  777.     move.l    4.w,a6
  778.     jsr    _LVOFreeVec(a6)
  779.     rts
  780.  
  781. SurrenderLI
  782.     IFND    DEBUG
  783.     movem.l    d0-d1/a0-a1/a6,-(sp)
  784.     lea    sc_LayerInfo(a5),a0
  785.     move.l    Layers.Base(pc),a6
  786.     jsr    _LVOUnlockLayerInfo(a6)
  787.     movem.l    (sp)+,d0-d1/a0-a1/a6
  788.     ENDC
  789.     rts
  790.  
  791. StrLen    ; (D0,Z)Len=StrLen(String)(A0)
  792.     move.l    a0,-(sp)
  793.     move.l    a0,d0
  794. .Loop    tst.b    (a0)+
  795.     bne.s    .Loop
  796.     sub.l    d0,a0
  797.     move.l    a0,d0
  798.     move.l    (sp)+,a0
  799.     subq.l    #1,d0
  800.     rts
  801.  
  802. EasyPrint    dc.l    es_SIZEOF
  803.     dc.l    0
  804.     dc.l    EasyPrint.Title
  805.     dc.l    0
  806.     dc.l    EasyPrint.Gad
  807.  
  808. Screen2IFF.NewBroker
  809.     dc.b    NB_VERSION,0
  810.     dc.l    Screen2IFF.Name
  811.     dc.l    Screen2IFF.Title
  812.     dc.l    Screen2IFF.Descr
  813.     dc.w    NBU_UNIQUE!NBU_NOTIFY
  814.     dc.w    0
  815.     dc.b    10,0
  816. CXPort    dc.l    0
  817.     dc.w    0
  818.  
  819. CXBroker    dc.l    0
  820. CXError    dc.l    0
  821.  
  822. SaveScreen.HKD    dc.l    IE_SAVESCREEN,SaveScreen.Descr,SaveScreen.Def
  823.  
  824. Args.Array
  825. SaveScreen.Descr
  826.     dc.l    0
  827. BaseName
  828.     dc.l    DefaultFile.Name
  829. CXPri    dc.l    0
  830.  
  831. SaveScreen.HK    dc.l    0
  832.  
  833. BMHD.Buffer
  834. BMHD.Wid    dc.w    0
  835. BMHD.H    dc.w    0
  836.     dc.w    0,0
  837. BMHD.nPlanes    dc.b    0,0
  838. BMHD.Compression    dc.b    0,0    ; not compressed (yet?)
  839.     dc.w    0,$0101
  840. BMHD.pageWidth    dc.w    0
  841. BMHD.pageHeight    dc.w    0
  842. BMHD.SIZEOF=*-BMHD.Buffer
  843.  
  844. NColors    dc.l    0
  845. CMap    dc.l    0
  846.  
  847. CAMG    dc.l    0
  848.  
  849. Bitplanes.Copy    dc.l    0
  850. Body.Size    dc.l    0
  851.  
  852. Args.RDArgs    dc.l    0
  853. Program.DiskObject    dc.l    0
  854.  
  855. SaveFile.Handle    dc.l    0
  856. SaveFile.IFF    dc.l    0
  857.  
  858. Intuition.Base    dc.l    0
  859. DOS.Base    dc.l    0
  860. Icon.Base    dc.l    0
  861. Graphics.Base    dc.l    0
  862. Layers.Base    dc.l    0
  863. Commodities.Base    dc.l    0
  864. IFFParse.Base    dc.l    0
  865.  
  866. Graphics.Name    dc.b    'graphics.library',0
  867. Layers.Name    dc.b    'layers.library',0
  868. Commodities.Name    dc.b    'commodities.library',0
  869. IFFParse.Name    dc.b    'iffparse.library',0
  870. Icon.Name    dc.b    'icon.library',0
  871. Screen2IFF.Name    dc.b    'Screen2IFF',0
  872. DefaultFile.Name    dc.b    'ScreenA',0
  873.  
  874. NoCommodities.MSG    dc.b    'Unable to open commodities.library V37+ !',0
  875. NoIFFParse.MSG    dc.b    'Unable to open iffparse.library V37+ !',0
  876. NotEnoughMem.MSG    dc.b    'Not enough memory !',0
  877. UnknownCXError.MSG    dc.b    'Commodities reports an unknown error !',0
  878. Removed.MSG    dc.b    'Removed Screen2IFF',0
  879. BadHotKeyDescr.MSG    dc.b    'Bad hotkey description string.',10
  880.     dc.b    'Default used.',0
  881. UnknownCXMessage.MSG    dc.b    'Unknown Commodities message received !',10
  882.     dc.b    '(This is VERY strange !)',0
  883. CantOpenSaveFile.MSG    dc.b    'Cannot open save file !',0
  884. ErrorWriting.MSG    dc.b    'Error writing output file !',0
  885.  
  886. EasyPrint.Title    dc.b    'Message from Screen2IFF:',0
  887. EasyPrint.Gad    dc.b    'Aha.',0
  888. Screen2IFF.Title    dc.b    'Screen2IFF '
  889.     REVISION
  890.     dc.b    ' © 1994 F.Delacroix',0
  891. Screen2IFF.Descr    dc.b    'Saves screen when hotkey pressed.',0
  892.  
  893. SaveScreen.Def    dc.b    'lcommand rcommand f10',0
  894.  
  895. BadKickstart.ALT    dc.b    0,176,14
  896.     dc.b    'You need kickstart V37.175 (2.04) !',0,0
  897. BadKickstart.HGT    EQU    24
  898.